package org.rcy.framework.data.dao;

import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.type.TypeHandler;
import tk.mybatis.mapper.entity.EntityColumn;
import tk.mybatis.mapper.entity.EntityField;

public class IdEntityHandler {
    private static final Log log = LogFactory.getLog(EntityResolveImpl.class);
    private static Class ID_ENTITY_CLASS;

    public IdEntityHandler() {
    }

    public static void handleIdEntity(EntityColumn entityColumn, EntityField field) {
        try {
            if (getIdEntityClass().isAssignableFrom(field.getJavaType())) {
                Class<?> idHandler = Class.forName("org.rcy.framework.data.dao.IdHandler");
                entityColumn.setTypeHandler((Class<? extends TypeHandler<?>>) idHandler);
            }
        } catch (Exception var3) {
            log.error("handleIdEntity error " + var3.getMessage(), var3);
        }

    }

    public static Class getIdEntityClass() {
        if (ID_ENTITY_CLASS != null) {
            return ID_ENTITY_CLASS;
        } else {
            try {
                ID_ENTITY_CLASS = Class.forName("org.rcy.framework.api.entity.IdEntity");
            } catch (Exception var1) {
                return null;
            }

            return ID_ENTITY_CLASS;
        }
    }
}
